$(function () {
    obj.init();

});

var obj = new function () {
    'use strict';
    return {
        dataGrid:null,
        titleRow:null,
        tabRow:null,
        type: null,
        init:function () {
            this.type    = location.pathname.split("/").pop();
            this.titleRow = $('#titleRow');
            this.tabRow   = $('#tabRow');
            this.dataGrid = new xhDataGrid($('#list'), 'coop/getInfo/'+this.type);
            this.dataGrid.parseToolbar().init().activeButton(['bt_list_del'], []);
            this.funObj().bindDataGridEvent();
            this.listener();
        },
        listener:function () {
            var $this = this;

            //新增事件按钮
            $('#bt_list_add').on('click',function () {
                $this.funObj().openAddForm();
            });

            $('#bt_list_del').on('click',function () {
                $this.funObj().askDelQuestion();
            });

            $('#tabReturn').on('click',function () {
                $this.funObj().goToList();
            });
        },
        funObj:function () {
            var $this = this;
            return {
                bindDataGridEvent:function () {
                    $this.dataGrid.onDblClickRow = function (rowIndex, rowData) {
                        $('#title').contents()[0]['data'] = rowData['sName'];
                        window.frames['tabFrame'].location.href = baseUrl+'coop/coopTab/'+$this.type+'/'+rowData['iCIId'];
                        $this.titleRow.show();
                        $this.tabRow.show();
                        xhExtra.forwardToForm(true);
                    }
                },
                openAddForm:function () {
                    window.top.xhTop.showModal({
                        title: '新增合伙人',
                        content: '<iframe  src="'+baseUrl+'coop/addForm/'+$this.type+'"  style="width: 100%;;border-style: none;padding: 0px;height:300px"  scrolling="yes"   ></iframe>',
                        button:'提交'
                    });
                },
                goToList:function () {
                    $this.titleRow.hide();
                    $this.tabRow.hide();
                    $this.dataGrid.reload();
                    xhExtra.backToList();

                },
                askDelQuestion:function () {
                    var ids = $this.dataGrid.getSelectValues('iCIId');
                    xhExtra.askChangeStatus('coop/delInfo/'+$this.type,{ids:ids},null,null,function (res) {
                        window.top.xhTop.showSuccess(res.msg);
                        $this.dataGrid.reload();
                    });
                }
            }
        }
    }
};